home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / hardware / galer21.lha / GALer21 / Source / GALer / Reasm.c < prev    next >
C/C++ Source or Header  |  1996-04-05  |  62KB  |  1,832 lines

  1. /******************************************************************************
  2. ** Reasm.c
  3. *******************************************************************************
  4. **
  5. ** description:
  6. **
  7. ** This file contains some subroutines for GALer's reassembler.
  8. **
  9. ******************************************************************************/
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16. /********************************* includes **********************************/
  17.  
  18. #include <libraries/mui.h>
  19.  
  20. #include <exec/memory.h>
  21. #include <libraries/dos.h>
  22. #include <intuition/intuition.h>
  23. #include <intuition/gadgetclass.h>
  24. #include <libraries/gadtools.h>
  25. #include <libraries/locale.h>
  26. #include <ctype.h>
  27. #include <string.h>
  28.  
  29. #include <proto/locale.h>
  30. #include <proto/intuition.h>
  31. #include <proto/gadtools.h>
  32. #include <proto/exec.h>
  33. #include <proto/dos.h>
  34. #include <proto/muimaster.h>
  35.  
  36. #include "GALer.h"
  37. #include "Localize.h"
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44. /********************************** defines **********************************/
  45.  
  46. #define RASM_ID01            1       /* gadget IDs and the pin numbers */
  47. #define RASM_ID02            2       /* must be the same               */
  48. #define RASM_ID03            3
  49. #define RASM_ID04            4
  50. #define RASM_ID05            5
  51. #define RASM_ID06            6
  52. #define RASM_ID07            7
  53. #define RASM_ID08            8
  54. #define RASM_ID09            9
  55. #define RASM_ID10            10
  56. #define RASM_ID11            11
  57. #define RASM_ID12            12
  58. #define RASM_ID13            13
  59. #define RASM_ID14            14
  60. #define RASM_ID15            15
  61. #define RASM_ID16            16
  62. #define RASM_ID17            17
  63. #define RASM_ID18            18
  64. #define RASM_ID19            19
  65. #define RASM_ID20            20
  66. #define RASM_ID21            21
  67. #define RASM_ID22            22
  68. #define RASM_ID23            23
  69. #define RASM_ID24            24
  70.  
  71. #define RASM_OK_ID           30
  72. #define RASM_CANCEL_ID       31
  73. #define RASM_SET_ID          32
  74. #define RASM_CLEAR_ID        33
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81. /******************************** functions **********************************/
  82.  
  83. static void   SetPinNames(int galtype);
  84.  
  85. static int    CheckPinNames(int galtype);
  86.  
  87. static int    PinNameRequester(int galtype);
  88.  
  89. static int    RowActive(int row, int galtype);
  90.  
  91. static int    OLMCOutput(int olmc, int mode);
  92.  
  93. static int    MakeEquation(struct ActBuffer *buff, int olmc, int colsize,
  94.                            int mode, int rowoffset, int numofrows);
  95.  
  96. static int    Reasm(struct ActBuffer buff);
  97.  
  98. static void   ReasmError(int errornum, int pinnum);
  99.  
  100. static char  *PinNamePtr(int pinnum);
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107. /******************************** variables **********************************/
  108.  
  109. extern  struct  AppString { LONG   as_ID;
  110.                             STRPTR as_Str;
  111.                           };
  112.  
  113. extern  struct  AppString AppStrings[];
  114.  
  115. extern  int OLMCSize22V10[];
  116.  
  117. extern  int ToOLMC20RA10[];
  118.  
  119.  
  120. extern  char    path[];
  121. extern  int     JedecGALType;
  122. extern  char    filename[];                     /*Puffer für Filenamen*/
  123. extern  struct  JedecStruct     Jedec;
  124. extern  struct  Catalog         *catalog;
  125.  
  126. extern  APTR    app;
  127.  
  128.  
  129.  
  130.  
  131.                                         /* this vectors show which column of */
  132.                                         /* the logic array is connected to   */
  133.                                         /* which pin                         */
  134. int FuseToPin16Mode1[] = { 2,1,3,19,4,18,5,17,6,14,7,13,8,12,9,11 };
  135. int FuseToPin16Mode2[] = { 2,1,3,18,4,17,5,16,6,15,7,14,8,13,9,11 };
  136. int FuseToPin16Mode3[] = { 2,19,3,18,4,17,5,16,6,15,7,14,8,13,9,12 };
  137.  
  138. int FuseToPin20Mode1[] = { 2,1,3,23,4,22,5,21,6,20,7,17,8,16,9,15,10,14,11,13 };
  139. int FuseToPin20Mode2[] = { 2,1,3,23,4,21,5,20,6,19,7,18,8,17,9,16,10,14,11,13 };
  140. int FuseToPin20Mode3[] = { 2,23,3,22,4,21,5,20,6,19,7,18,8,17,9,16,10,15,11,14 };
  141.  
  142. int FuseToPin22V10[]   = { 1,23,2,22,3,21,4,20,5,19,6,18,7,17,8,16,9,15,10,14,11,13 };
  143.  
  144. int FuseToPin20RA10[]  = { 2,23,3,22,4,21,5,20,6,19,7,18,8,17,9,16,10,15,11,14 };
  145.  
  146.  
  147.                                         /* this vector shows which OLMC is */
  148.                                         /* connected to which row          */
  149.  
  150. int OLMCToRow22V10[]   = { 1, 10, 21, 34, 49, 66, 83, 98, 111, 122 };
  151.  
  152.  
  153.                                         /* pin names for 20 pins package */
  154.  
  155. char  ReAsmPinNames20[20][10] = { "P1",  "P2",  "P3",  "P4",
  156.                                   "P5",  "P6",  "P7",  "P8",
  157.                                   "P9",  "GND", "P11", "P12",
  158.                                   "P13", "P14", "P15", "P16",
  159.                                   "P17", "P18", "P19", "VCC"
  160.                                 };
  161.  
  162.                                         /* pin names for 24 pins package */
  163.  
  164. char  ReAsmPinNames24[24][10] = { "P1",  "P2",  "P3",  "P4",
  165.                                   "P5",  "P6",  "P7",  "P8",
  166.                                   "P9",  "P10", "P11", "GND",
  167.                                   "P13", "P14", "P15", "P16",
  168.                                   "P17", "P18", "P19", "P20",
  169.                                   "P21", "P22", "P23", "VCC",
  170.                                 };
  171.  
  172. APTR    strng_gad[24];
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181. /******************************************************************************
  182. ** SetPinNames()
  183. *******************************************************************************
  184. ** input:   galtype     type of GAL
  185. **
  186. ** output:  none
  187. **
  188. ** remarks: This function does initialize the strings of the string gadgets
  189. **          of the reassembler requester.
  190. ******************************************************************************/
  191.  
  192. static void SetPinNames(int galtype)
  193. {
  194.     int     n, num_of_pins;
  195.  
  196.     char    name[4], numstrng[3];
  197.  
  198.  
  199.  
  200.     if (galtype == GAL16V8)                     /* get number of pins */
  201.         num_of_pins = 20;
  202.     else
  203.         num_of_pins = 24;
  204.  
  205.  
  206.     for (n = 1; n <= num_of_pins; n++)          /* set the pin names to */
  207.     {                                           /* there defaults       */
  208.         if (n == num_of_pins/2)
  209.         {
  210.             set(strng_gad[n-1], MUIA_String_Contents, "GND");
  211.         }
  212.         else
  213.         {
  214.             if (n == num_of_pins)
  215.             {
  216.                 set(strng_gad[n-1], MUIA_String_Contents, "VCC");
  217.             }
  218.             else
  219.             {
  220.                 name[0] = 'P';
  221.                 name[1] = (char)0;
  222.  
  223.                 sprintf(numstrng, "%d", n);         /* make the pin number  */
  224.  
  225.                 strcat(name, numstrng);             /* add it to the string */
  226.  
  227.                 set(strng_gad[n-1], MUIA_String_Contents, name);
  228.             }
  229.         }
  230.     }
  231.  
  232. }
  233.  
  234.  
  235.  
  236.  
  237.  
  238. /******************************************************************************
  239. ** PinNamePtr()
  240. *******************************************************************************
  241. ** input:   pinnum      pin number
  242. **                      whether it is a valid number or not will NOT be
  243. **                      checked!
  244. **
  245. ** output:  none
  246. **
  247. ** remarks: This function returns a pointer to the pin name of the pin
  248. **          with the pin number "pinnum". The returned string must not be
  249. **          changed!
  250. ******************************************************************************/
  251.  
  252. static char *PinNamePtr(int pinnum)
  253. {
  254.     char  *name;
  255.  
  256.  
  257.     if (JedecGALType == GAL16V8)
  258.         name = &ReAsmPinNames20[pinnum - 1][0];     /* 20 pins package */
  259.     else
  260.         name = &ReAsmPinNames24[pinnum - 1][0];     /* 24 pins package */
  261.  
  262.  
  263.     return name;
  264. }
  265.  
  266.  
  267.  
  268.  
  269.  
  270. /******************************************************************************
  271. ** CheckPinNames()
  272. *******************************************************************************
  273. ** input:   galtype     type of GAL
  274. **
  275. ** output:    0: o.k.
  276. **          <>0: error occured
  277. **
  278. ** remarks: checks syntax of the pinnames
  279. ******************************************************************************/
  280.  
  281. static int CheckPinNames(int galtype)
  282. {
  283.     char    *name;
  284.     int     numofpins, i, j, l, n;
  285.  
  286.  
  287.  
  288.     if (JedecGALType == GAL16V8)
  289.         numofpins = 20;
  290.     else
  291.         numofpins = 24;
  292.  
  293.  
  294.                                         /*** check the pin names ***/
  295.     for (n = 0; n < numofpins; n++)
  296.     {
  297.  
  298.                                     /* get a pointer to the */
  299.         name = PinNamePtr(n + 1);   /* pin name             */
  300.  
  301.  
  302.                                             /* are all characters of the */
  303.                                             /* pin name allowed?         */
  304.         if (*name == '/')
  305.             name++;
  306.  
  307.         if (!*name)
  308.         {                                   /* no characters? => error */
  309.             ReasmError(4, n+1);
  310.             return(4);
  311.         }
  312.  
  313.                                                  /* set pointer to next    */
  314.         while (isalpha(*name) || isdigit(*name)) /* character which is not */
  315.             name++;                              /* a digit or a letter    */
  316.  
  317.  
  318.         if (*name == '/')                   /* negation within the string? */
  319.         {                                   /* this is illegal!            */
  320.             ReasmError(6, n+1);
  321.             return(6);
  322.         }
  323.  
  324.         if (*name)                          /* any illegal character */
  325.         {
  326.             ReasmError(3, n+1);
  327.             return(3);
  328.         }
  329.  
  330.                                             /* check whether some pin names */
  331.         for (l = 0; l < n; l++)             /* are defined twice or not     */
  332.         {
  333.  
  334.             if (strcmp(PinNamePtr(l + 1), "NC")) /* NC is allowed to occure */
  335.             {                                    /* several times           */
  336.                 i = j = 0;
  337.  
  338.                 if (*(PinNamePtr(l + 1)) == '/')      /* skip the negations */
  339.                     i = 1;
  340.  
  341.                 if (*(PinNamePtr(n + 1)) == '/')
  342.                     j = 1;
  343.  
  344.                 if (!strcmp(PinNamePtr(l + 1) + i, PinNamePtr(n + 1) + j))
  345.                 {
  346.                     ReasmError(2, n + 1);      /* pin name is defined twice */
  347.                     return(2);
  348.                 }
  349.             }
  350.         }
  351.  
  352.                                           /*GND as pin name at GAL's GND pin?*/
  353.  
  354.         if (!strcmp(PinNamePtr(n+1), "GND"))
  355.         {
  356.             if (n + 1 != numofpins/2)
  357.             {
  358.                 ReasmError(5, n + 1);
  359.                 return(5);
  360.             }
  361.         }
  362.  
  363.         if (n + 1 == numofpins/2)
  364.         {
  365.             if (strcmp(PinNamePtr(n + 1), "GND"))
  366.             {
  367.                 ReasmError(7, n + 1);
  368.                 return(7);
  369.             }
  370.         }
  371.                                           /*VCC as pin name at GAL's VCC pin?*/
  372.  
  373.         if (!strcmp(PinNamePtr(n + 1), "VCC"))
  374.         {
  375.             if (n + 1 != numofpins)
  376.             {
  377.                 ReasmError(5, n+1);
  378.                 return(5);
  379.             }
  380.         }
  381.  
  382.         if (n + 1 == numofpins)
  383.         {
  384.             if (strcmp(PinNamePtr(n + 1), "VCC"))
  385.             {
  386.                 ReasmError(8, n+1);
  387.                 return(8);
  388.             }
  389.         }
  390.                                           /* AR and SP are key words for 22V10 */
  391.                                           /* they are not allowed in the pin   */
  392.                                           /* declaration                       */
  393.         if (JedecGALType == GAL22V10)
  394.         {
  395.             if (!strcmp(PinNamePtr(n + 1), "AR"))
  396.             {
  397.                 ReasmError(9, n + 1);
  398.                 return(9);
  399.             }
  400.  
  401.             if (!strcmp(PinNamePtr(n + 1), "SP"))
  402.             {
  403.                 ReasmError(10, n+1);
  404.                 return(10);
  405.             }
  406.         }
  407.     }
  408.  
  409.  
  410.     return(0);
  411. }
  412.  
  413.  
  414.  
  415.  
  416.  
  417. /******************************************************************************
  418. ** PinNameRequester()
  419. *******************************************************************************
  420. ** input:   galtype     type of GAL
  421. **
  422. ** output:  TRUE:  continue selected
  423. **          FALSE: cancel selected or error
  424. **
  425. ** remarks: brings up a requester in which the names of the pins can be edited
  426. ******************************************************************************/
  427.  
  428. static int PinNameRequester(int galtype)
  429. {
  430.     int     n, open, done, result, num_of_pins;
  431.  
  432.     ULONG   id, signals;
  433.  
  434.     APTR    win;
  435.     APTR    ok_gad, cancel_gad, set_gad, clear_gad;
  436.  
  437.     STRPTR  *str;
  438.  
  439.  
  440.  
  441.  
  442.     set(app, MUIA_Application_Sleep, TRUE);     /* deactivate application */
  443.  
  444.                                                 /* make window object */
  445.  
  446.     if (galtype == GAL16V8)                     /* 20 pin package */
  447.     {
  448.  
  449.         num_of_pins = 20;
  450.  
  451.         win = WindowObject,
  452.             MUIA_Window_Title, "Reassembler",
  453.             MUIA_Window_CloseGadget, FALSE,
  454.             MUIA_Window_NoMenus, TRUE,
  455.             MUIA_HelpNode, "MenReAsm",
  456.  
  457.             WindowContents, GroupObject,
  458.  
  459.                 Child, ColGroup(4), GroupFrameT("GAL"),
  460.                     MUIA_Group_VertSpacing, 0,
  461.  
  462.                                                 /* pins 1 and 20 */
  463.                     Child, strng_gad[0] = StringObject, StringFrame,
  464.                              MUIA_String_MaxLen, 10,
  465.                              MUIA_String_Contents, &ReAsmPinNames20[0][0],
  466.                              MUIA_String_Format, MUIV_String_Format_Right,
  467.                              End,
  468.                     Child, Label2("1"),
  469.  
  470.                     Child, Label2("20"),
  471.                     Child, strng_gad[19] = String(&ReAsmPinNames20[19][0], 10),
  472.  
  473.                                                 /* pins 2 and 19 */
  474.                     Child, strng_gad[1] = StringObject, StringFrame,
  475.                              MUIA_String_MaxLen, 10,
  476.                              MUIA_String_Contents, &ReAsmPinNames20[1][0],
  477.                              MUIA_String_Format, MUIV_String_Format_Right,
  478.                              End,
  479.                     Child, Label2("2"),
  480.  
  481.                     Child, Label2("19"),
  482.                     Child, strng_gad[18] = String(&ReAsmPinNames20[18][0], 10),
  483.  
  484.                                                 /* pins 3 and 18 */
  485.                     Child, strng_gad[2] = StringObject, StringFrame,
  486.                              MUIA_String_MaxLen, 10,
  487.                              MUIA_String_Contents, &ReAsmPinNames20[2][0],
  488.                              MUIA_String_Format, MUIV_String_Format_Right,
  489.                              End, 
  490.                     Child, Label2("3"),
  491.  
  492.                     Child, Label2("18"),
  493.                     Child, strng_gad[17] = String(&ReAsmPinNames20[17][0], 10),
  494.  
  495.                                                 /* pins 4 and 17 */
  496.                     Child, strng_gad[3] = StringObject, StringFrame,
  497.                              MUIA_String_MaxLen, 10,
  498.                              MUIA_String_Contents, &ReAsmPinNames20[3][0],
  499.                              MUIA_String_Format, MUIV_String_Format_Right,
  500.                              End, 
  501.                     Child, Label2("4"),
  502.  
  503.                     Child, Label2("17"),
  504.                     Child, strng_gad[16] = String(&ReAsmPinNames20[16][0], 10),
  505.  
  506.                                                 /* pins 5 and 16 */
  507.                     Child, strng_gad[4] = StringObject, StringFrame,
  508.                              MUIA_String_MaxLen, 10,
  509.                              MUIA_String_Contents, &ReAsmPinNames20[4][0],
  510.                              MUIA_String_Format, MUIV_String_Format_Right,
  511.                              End, 
  512.                     Child, Label2("5"),
  513.  
  514.                     Child, Label2("16"),
  515.                     Child, strng_gad[15] = String(&ReAsmPinNames20[15][0], 10),
  516.  
  517.                                                 /* pins 6 and 15 */
  518.                     Child, strng_gad[5] = StringObject, StringFrame,
  519.                              MUIA_String_MaxLen, 10,
  520.                              MUIA_String_Contents, &ReAsmPinNames20[5][0],
  521.                              MUIA_String_Format, MUIV_String_Format_Right,
  522.                              End, 
  523.                     Child, Label2("6"),
  524.  
  525.                     Child, Label2("15"),
  526.                     Child, strng_gad[14] = String(&ReAsmPinNames20[14][0], 10),
  527.  
  528.                                                 /* pins 7 and 14 */
  529.                     Child, strng_gad[6] = StringObject, StringFrame,
  530.                              MUIA_String_MaxLen, 10,
  531.                              MUIA_String_Contents, &ReAsmPinNames20[6][0],
  532.                              MUIA_String_Format, MUIV_String_Format_Right,
  533.                              End, 
  534.                     Child, Label2("7"),
  535.  
  536.                     Child, Label2("14"),
  537.                     Child, strng_gad[13] = String(&ReAsmPinNames20[13][0], 10),
  538.  
  539.                                                 /* pins 8 and 13 */
  540.                     Child, strng_gad[7] = StringObject, StringFrame,
  541.                              MUIA_String_MaxLen, 10,
  542.                              MUIA_String_Contents, &ReAsmPinNames20[7][0],
  543.                              MUIA_String_Format, MUIV_String_Format_Right,
  544.                              End, 
  545.                     Child, Label2("8"),
  546.  
  547.                     Child, Label2("13"),
  548.                     Child, strng_gad[12] = String(&ReAsmPinNames20[12][0], 10),
  549.  
  550.                                                 /* pins 9 and 12 */
  551.                     Child, strng_gad[8] = StringObject, StringFrame,
  552.                              MUIA_String_MaxLen, 10,
  553.                              MUIA_String_Contents, &ReAsmPinNames20[8][0],
  554.                              MUIA_String_Format, MUIV_String_Format_Right,
  555.                              End, 
  556.                     Child, Label2("9"),
  557.  
  558.                     Child, Label2("12"),
  559.                     Child, strng_gad[11] = String(&ReAsmPinNames20[11][0], 10),
  560.  
  561.                                                 /* pins 10 and 11 */
  562.                     Child, strng_gad[9] = StringObject, StringFrame,
  563.                              MUIA_String_MaxLen, 10,
  564.                              MUIA_String_Contents, &ReAsmPinNames20[9][0],
  565.                              MUIA_String_Format, MUIV_String_Format_Right,
  566.                              End, 
  567.                     Child, Label2("10"),
  568.  
  569.                     Child, Label2("11"),
  570.                     Child, strng_gad[10] = String(&ReAsmPinNames20[10][0], 10),
  571.  
  572.                     End,
  573.      
  574.                 Child, HGroup,
  575.                     Child, ok_gad = SimpleButton(AppStrings[MSG_OK_GAD].as_Str),
  576.  
  577.                     Child, set_gad = SimpleButton(AppStrings[MSG_SET_GAD].as_Str),
  578.  
  579.                     Child, clear_gad = SimpleButton(AppStrings[MSG_CLEAR_GAD].as_Str),
  580.  
  581.                     Child, cancel_gad = SimpleButton(AppStrings[MSG_CANCEL_GAD].as_Str),
  582.  
  583.                     End,
  584.                 End,
  585.             End;
  586.     }
  587.     else
  588.     {
  589.         num_of_pins = 24;
  590.  
  591.         win = WindowObject,
  592.             MUIA_Window_Title, "Reassembler",
  593.             MUIA_Window_CloseGadget, FALSE,
  594.             MUIA_Window_NoMenus, TRUE,
  595.  
  596.             WindowContents, GroupObject,
  597.  
  598.                 Child, ColGroup(4), GroupFrameT("GAL"),
  599.                     MUIA_Group_VertSpacing, 0,
  600.      
  601.                                                 /* pins 1 and 24 */
  602.                     Child, strng_gad[0] = StringObject, StringFrame,
  603.                              MUIA_String_MaxLen, 10,
  604.                              MUIA_String_Contents, &ReAsmPinNames24[0][0],
  605.                              MUIA_String_Format, MUIV_String_Format_Right,
  606.                              End, 
  607.                     Child, Label2("1"),
  608.  
  609.                     Child, Label2("24"),
  610.                     Child, strng_gad[23] = String(&ReAsmPinNames24[23][0], 10),
  611.  
  612.                                                 /* pins 2 and 23 */
  613.                     Child, strng_gad[1] = StringObject, StringFrame,
  614.                              MUIA_String_MaxLen, 10,
  615.                              MUIA_String_Contents, &ReAsmPinNames24[1][0],
  616.                              MUIA_String_Format, MUIV_String_Format_Right,
  617.                              End, 
  618.                     Child, Label2("2"),
  619.  
  620.                     Child, Label2("23"),
  621.                     Child, strng_gad[22] = String(&ReAsmPinNames24[22][0], 10),
  622.  
  623.                                                 /* pins 3 and 22 */
  624.                     Child, strng_gad[2] = StringObject, StringFrame,
  625.                              MUIA_String_MaxLen, 10,
  626.                              MUIA_String_Contents, &ReAsmPinNames24[2][0],
  627.                              MUIA_String_Format, MUIV_String_Format_Right,
  628.                              End, 
  629.                     Child, Label2("3"),
  630.  
  631.                     Child, Label2("22"),
  632.                     Child, strng_gad[21] = String(&ReAsmPinNames24[21][0], 10),
  633.  
  634.                                                 /* pins 4 and 21 */
  635.                     Child, strng_gad[3] = StringObject, StringFrame,
  636.                              MUIA_String_MaxLen, 10,
  637.                              MUIA_String_Contents, &ReAsmPinNames24[3][0],
  638.                              MUIA_String_Format, MUIV_String_Format_Right,
  639.                              End, 
  640.                     Child, Label2("4"),
  641.  
  642.                     Child, Label2("21"),
  643.                     Child, strng_gad[20] = String(&ReAsmPinNames24[20][0], 10),
  644.  
  645.                                                 /* pins 5 and 20 */
  646.                     Child, strng_gad[4] = StringObject, StringFrame,
  647.                              MUIA_String_MaxLen, 10,
  648.                              MUIA_String_Contents, &ReAsmPinNames24[4][0],
  649.                              MUIA_String_Format, MUIV_String_Format_Right,
  650.                              End, 
  651.                     Child, Label2("5"),
  652.  
  653.                     Child, Label2("20"),
  654.                     Child, strng_gad[19] = String(&ReAsmPinNames24[19][0], 10),
  655.  
  656.                                                 /* pins 6 and 19 */
  657.                     Child, strng_gad[5] = StringObject, StringFrame,
  658.                              MUIA_String_MaxLen, 10,
  659.                              MUIA_String_Contents, &ReAsmPinNames24[5][0],
  660.                              MUIA_String_Format, MUIV_String_Format_Right,
  661.                              End, 
  662.                     Child, Label2("6"),
  663.  
  664.                     Child, Label2("19"),
  665.                     Child, strng_gad[18] = String(&ReAsmPinNames24[18][0], 10),
  666.  
  667.                                                 /* pins 7 and 18 */
  668.                     Child, strng_gad[6] = StringObject, StringFrame,
  669.                              MUIA_String_MaxLen, 10,
  670.                              MUIA_String_Contents, &ReAsmPinNames24[6][0],
  671.                              MUIA_String_Format, MUIV_String_Format_Right,
  672.                              End, 
  673.                     Child, Label2("7"),
  674.  
  675.                     Child, Label2("18"),
  676.                     Child, strng_gad[17] = String(&ReAsmPinNames24[17][0], 10),
  677.  
  678.                                                 /* pins 8 and 17 */
  679.                     Child, strng_gad[7] = StringObject, StringFrame,
  680.                              MUIA_String_MaxLen, 10,
  681.                              MUIA_String_Contents, &ReAsmPinNames24[7][0],
  682.                              MUIA_String_Format, MUIV_String_Format_Right,
  683.                              End, 
  684.                     Child, Label2("8"),
  685.  
  686.                     Child, Label2("17"),
  687.                     Child, strng_gad[16] = String(&ReAsmPinNames24[16][0], 10),
  688.  
  689.                                                 /* pins 9 and 16 */
  690.                     Child, strng_gad[8] = StringObject, StringFrame,
  691.                              MUIA_String_MaxLen, 10,
  692.                              MUIA_String_Contents, &ReAsmPinNames24[8][0],
  693.                              MUIA_String_Format, MUIV_String_Format_Right,
  694.                              End, 
  695.                     Child, Label2("9"),
  696.  
  697.                     Child, Label2("16"),
  698.                     Child, strng_gad[15] = String(&ReAsmPinNames24[15][0], 10),
  699.  
  700.                                                 /* pins 10 and 15 */
  701.                     Child, strng_gad[9] = StringObject, StringFrame,
  702.                              MUIA_String_MaxLen, 10,
  703.                              MUIA_String_Contents, &ReAsmPinNames24[9][0],
  704.                              MUIA_String_Format, MUIV_String_Format_Right,
  705.                              End, 
  706.                     Child, Label2("10"),
  707.  
  708.                     Child, Label2("15"),
  709.                     Child, strng_gad[14] = String(&ReAsmPinNames24[14][0], 10),
  710.  
  711.                                                 /* pins 11 and 14 */
  712.                     Child, strng_gad[10] = StringObject, StringFrame,
  713.                              MUIA_String_MaxLen, 10,
  714.                              MUIA_String_Contents, &ReAsmPinNames24[10][0],
  715.                              MUIA_String_Format, MUIV_String_Format_Right,
  716.                              End, 
  717.                     Child, Label2("11"),
  718.  
  719.                     Child, Label2("14"),
  720.                     Child, strng_gad[13] = String(&ReAsmPinNames24[13][0], 10),
  721.  
  722.                                                 /* pins 12 and 13 */
  723.                     Child, strng_gad[11] = StringObject, StringFrame,
  724.                              MUIA_String_MaxLen, 10,
  725.                              MUIA_String_Contents, &ReAsmPinNames24[11][0],
  726.                              MUIA_String_Format, MUIV_String_Format_Right,
  727.                              End, 
  728.                     Child, Label2("12"),
  729.  
  730.                     Child, Label2("13"),
  731.                     Child, strng_gad[12] = String(&ReAsmPinNames24[12][0], 10),
  732.  
  733.                     End,
  734.      
  735.                 Child, HGroup,
  736.                     Child, ok_gad = SimpleButton(AppStrings[MSG_OK_GAD].as_Str),
  737.  
  738.                     Child, set_gad = SimpleButton(AppStrings[MSG_SET_GAD].as_Str),
  739.  
  740.                     Child, clear_gad = SimpleButton(AppStrings[MSG_CLEAR_GAD].as_Str),
  741.  
  742.                     Child, cancel_gad = SimpleButton(AppStrings[MSG_CANCEL_GAD].as_Str),
  743.  
  744.                     End,
  745.                 End,
  746.             End;
  747.     }
  748.  
  749.  
  750.                                         /* set gadget IDs */
  751.  
  752.     DoMethod(ok_gad, MUIM_Notify, MUIA_Pressed, FALSE,
  753.              app, 2, MUIM_Application_ReturnID, RASM_OK_ID);
  754.  
  755.     DoMethod(set_gad, MUIM_Notify, MUIA_Pressed, FALSE,
  756.              app, 2, MUIM_Application_ReturnID, RASM_SET_ID);
  757.  
  758.     DoMethod(clear_gad, MUIM_Notify, MUIA_Pressed, FALSE,
  759.              app, 2, MUIM_Application_ReturnID, RASM_CLEAR_ID);
  760.  
  761.     DoMethod(cancel_gad, MUIM_Notify, MUIA_Pressed, FALSE,
  762.              app, 2, MUIM_Application_ReturnID, RASM_CANCEL_ID);
  763.  
  764.  
  765.     for (n = 0; n < num_of_pins; n++)
  766.         DoMethod(strng_gad[n], MUIM_Notify, MUIA_Pressed, FALSE,
  767.                  app, 2, MUIM_Application_ReturnID, RASM_ID01 + n);
  768.  
  769.  
  770.  
  771.                                         /* init cycle chain */
  772.  
  773.     if (num_of_pins == 20)
  774.         DoMethod(win, MUIM_Window_SetCycleChain,
  775.                  strng_gad[ 0], strng_gad[ 1], strng_gad[ 2], strng_gad[ 3],
  776.                  strng_gad[ 4], strng_gad[ 5], strng_gad[ 6], strng_gad[ 7],
  777.                  strng_gad[ 8], strng_gad[ 9], strng_gad[10], strng_gad[11],
  778.                  strng_gad[12], strng_gad[13], strng_gad[14], strng_gad[15],
  779.                  strng_gad[16], strng_gad[17], strng_gad[18], strng_gad[19],
  780.                  ok_gad, set_gad, clear_gad, cancel_gad, NULL);
  781.     else
  782.         DoMethod(win, MUIM_Window_SetCycleChain,
  783.                  strng_gad[ 0], strng_gad[ 1], strng_gad[ 2], strng_gad[ 3],
  784.                  strng_gad[ 4], strng_gad[ 5], strng_gad[ 6], strng_gad[ 7],
  785.                  strng_gad[ 8], strng_gad[ 9], strng_gad[10], strng_gad[11],
  786.                  strng_gad[12], strng_gad[13], strng_gad[14], strng_gad[15],
  787.                  strng_gad[16], strng_gad[17], strng_gad[18], strng_gad[19],
  788.                  strng_gad[20], strng_gad[21], strng_gad[22], strng_gad[23],
  789.                  ok_gad, set_gad, clear_gad, cancel_gad, NULL);
  790.  
  791.  
  792.  
  793.  
  794.     if (win)                    /* window object created? */
  795.     {
  796.         DoMethod(app, OM_ADDMEMBER, win);       /* add win to application */
  797.  
  798.         set(win, MUIA_Window_Open, TRUE);       /* open window */
  799.         get(win, MUIA_Window_Open, &open);
  800.  
  801.         if (open)                               /* is window opened? */
  802.         {
  803.  
  804.  
  805.             done = FALSE;
  806.  
  807.             while (!done)
  808.             {
  809.                 id = DoMethod(app, MUIM_Application_Input, &signals);
  810.  
  811.  
  812.                 switch (id)
  813.                 {
  814.                     case RASM_OK_ID:            /* OK selected */
  815.  
  816.                                             /* copy names into buffers */
  817.  
  818.                         for (n = 0; n < num_of_pins; n++)
  819.                         {
  820.                             get(strng_gad[n], MUIA_String_Contents, &str);
  821.  
  822.                             if (num_of_pins == 20)  /* 20 pins package? */
  823.                                 strcpy(ReAsmPinNames20[n], (const char *)str);
  824.                             else
  825.                                 strcpy(ReAsmPinNames24[n], (const char *)str);
  826.                         }
  827.  
  828.                                        /* check the syntax of the pin names */
  829.  
  830.                         if (!CheckPinNames(galtype))
  831.                         {
  832.                             result = TRUE;
  833.                             done   = TRUE;      /* that's it  */
  834.                         }
  835.  
  836.                         break;
  837.  
  838.  
  839.                     case RASM_CANCEL_ID:
  840.  
  841.                         result = FALSE;         /* Cancel selected */
  842.                         done   = TRUE;          /* that's it */
  843.  
  844.                         break;
  845.  
  846.  
  847.                     case RASM_CLEAR_ID:         /* clear pin names */
  848.  
  849.                         for (n = 0; n < num_of_pins; n++)
  850.                             set(strng_gad[n], MUIA_String_Contents, "");
  851.  
  852.                         break;
  853.  
  854.                     case RASM_SET_ID:           /* set pin names */
  855.  
  856.                         SetPinNames(galtype);
  857.                         break;
  858.  
  859.                 }
  860.  
  861.  
  862.                 if (!done && signals)
  863.                     Wait(signals);              /* wait for the next event */
  864.             }
  865.  
  866.  
  867.            set(win, MUIA_Window_Open, FALSE);   /* close window */
  868.   
  869.         }
  870.  
  871.         DoMethod(app, OM_REMMEMBER, win);       /* remove win from app. */
  872.  
  873.         MUI_DisposeObject(win);                 /* delete window object */
  874.     }
  875.  
  876.  
  877.  
  878.     set(app, MUIA_Application_Sleep, FALSE);    /* reactivate application */
  879.  
  880.  
  881.     return result;
  882.  
  883. }
  884.  
  885.  
  886.  
  887.  
  888.  
  889. /******************************************************************************
  890. ** RowActive()
  891. *******************************************************************************
  892. ** input:   row         row which should be tested
  893. **          galtype     type of GAL
  894. **
  895. ** ouput:   0:          row is not active
  896. **          1:          row is active
  897. **          2:          row is active but includes only "1" (means VCC)
  898. **
  899. ** remarks: This function tests whether or not a row of the logic array is
  900. **          active (checks PT bits of the GAL16V8 and GAL20V8 and searchs
  901. **          for the expression A * /A).
  902. ******************************************************************************/
  903.  
  904. static int RowActive(int row, int galtype)
  905. {
  906.     int n, colsize, flag;
  907.  
  908.  
  909.     switch (galtype)
  910.     {                                       /* get number of columns */
  911.         case GAL16V8:
  912.             colsize = MAX_FUSE_ADR16 + 1;
  913.             break;
  914.  
  915.         case GAL20V8:
  916.             colsize = MAX_FUSE_ADR20 + 1;
  917.             break;
  918.  
  919.         case GAL22V10:
  920.             colsize = MAX_FUSE_ADR22V10 + 1;
  921.             break;
  922.  
  923.         case GAL20RA10:
  924.             colsize = MAX_FUSE_ADR20RA10 + 1;
  925.             break;
  926.     }
  927.  
  928.  
  929.     if (galtype == GAL16V8 || galtype == GAL20V8)
  930.         if (!Jedec.GALPT[row])              /* check PT-bit which     */
  931.             return(0);                      /* enables/disables a row */
  932.  
  933.  
  934.     flag = 0;
  935.  
  936.     for (n = 0; n < colsize; n++)
  937.     {                                       /* search for "A * /A" */
  938.         if (!Jedec.GALLogic[row*colsize + n])
  939.         {
  940.             flag = 1;
  941.  
  942.             if (!(n % 2))
  943.                 if (!Jedec.GALLogic[row*colsize + n + 1])
  944.                     return(0);
  945.         }
  946.     }
  947.  
  948.     if (flag)
  949.         return(1);
  950.     else
  951.         return(2);
  952. }
  953.  
  954.  
  955.  
  956.  
  957.  
  958. /******************************************************************************
  959. ** OLMCOutput()
  960. *******************************************************************************
  961. ** input:   olmc    OLMC which should be tested
  962. **          mode    mode of the GAL (only when 16V8/20V8)
  963. **
  964. ** output:      0: no output
  965. **              1: output (there is an equation which describes this
  966. **                 output pin)
  967. **
  968. ** remarks: checks whether or not an OLMC pin is programmed as an output
  969. ******************************************************************************/
  970.  
  971. static int OLMCOutput(int olmc, int mode)
  972. {
  973.     int n, flag;
  974.  
  975.  
  976.     flag = 0;
  977.  
  978.     if (JedecGALType == GAL16V8 || JedecGALType == GAL20V8)
  979.     {
  980.         if (mode == 1 && Jedec.GALAC1[olmc])
  981.             return(0);
  982.  
  983.         for (n = 0; n < 8; n++)
  984.         {
  985.             if (!n && ((mode == 2) || ((mode == 3) && Jedec.GALAC1[olmc])))
  986.             {
  987.                 if (!RowActive(olmc*8, JedecGALType)) /*tristate enable = GND?*/
  988.                     return(0);                        /*yes, then input pin   */
  989.             }
  990.             else
  991.             {
  992.                 if (RowActive(olmc*8 + n, JedecGALType))
  993.                     flag = 1;
  994.             }
  995.         }
  996.     }
  997.  
  998.  
  999.     if (JedecGALType == GAL22V10)           /* pin is an output when tristate */
  1000.         if (RowActive(OLMCToRow22V10[olmc], JedecGALType)) /* can be HIGH/LOW */
  1001.             return(1);
  1002.  
  1003.     if (JedecGALType == GAL20RA10)          /* pin is an output when tristate */
  1004.         if (RowActive(olmc*8, JedecGALType))               /* can be HIGH/LOW */
  1005.             return(1);
  1006.  
  1007.  
  1008.     return(flag);
  1009. }
  1010.  
  1011.  
  1012.  
  1013.  
  1014.  
  1015. /******************************************************************************
  1016. ** MakeEquation()
  1017. *******************************************************************************
  1018. ** input:   buff      pointer to the ActBuffer structure
  1019. **          olmc      number of the OLMC
  1020. **          colsize   number of columns
  1021. **          mode      mode of GAL
  1022. **                      0: no mode used
  1023. **                      1: combinational (only for GAL16V8/GAL20V8)
  1024. **                      2: tristate      (only for GAL16V8/GAL20V8)
  1025. **                      3: register      (only for GAL16V8/GAL20V8)
  1026. **                      4: asynchronous reset   (only for GAL22V10)
  1027. **                      5: snychronous  preset  (only for GAL22V10
  1028. **          rowoffset where to start to build the equation
  1029. **          numofrows number of rows from which the equation should be build
  1030. **
  1031. ** output:      0:    no errors
  1032. **             -1:    error occured (out of memory)
  1033. **
  1034. ** remarks: This function examines the rows of an OLMC and generates the
  1035. **          equation.
  1036. ******************************************************************************/
  1037.  
  1038. static int MakeEquation(struct ActBuffer *buff, int olmc, int colsize, int mode,
  1039.                         int rowoffset, int numofrows)
  1040. {
  1041.  
  1042.     int     ORflag, ANDflag, pin, m, n, result, numofchar;
  1043.     int     offset, row;
  1044.  
  1045.     struct  ActBuffer  startbuff;
  1046.  
  1047.  
  1048.  
  1049.  
  1050.     startbuff = *buff;                            /* save pointer*/
  1051.  
  1052.     numofchar = 8;
  1053.     ORflag    = 0;
  1054.  
  1055.     n = rowoffset;
  1056.  
  1057.     while (n < rowoffset + numofrows)
  1058.     {
  1059.  
  1060.         if (JedecGALType == GAL22V10)
  1061.         {                                       /* 22V10 => different sizes */
  1062.                                                 /* of OLMCs and additional  */
  1063.             row = OLMCToRow22V10[olmc];         /* AS and RS rows           */
  1064.  
  1065.             if (mode == 4)
  1066.                 row = 0;                        /* asynch. reset */
  1067.             else
  1068.                 if (mode == 5)
  1069.                     row = 131;                  /* synch. preset */
  1070.         }
  1071.         else
  1072.             row = olmc*8;                   /* 16V8,20V8,20RA10: OLMC size */
  1073.                                             /* is constant (=8)            */
  1074.  
  1075.         result = RowActive(row + n, JedecGALType);
  1076.  
  1077.  
  1078.         if (result == 1)
  1079.         {                                   /* is row active? */
  1080.  
  1081.             if (ORflag)
  1082.             {                               /* yes, then OR */
  1083.                 if (AddString(buff, (UBYTE *)" + "))
  1084.                     return(-1);
  1085.  
  1086.                 numofchar += 3;             /* count characters */
  1087.             }
  1088.  
  1089.  
  1090.             ORflag  = 1;
  1091.             ANDflag = 0;
  1092.  
  1093.             for (m = 0; m < colsize; m++)
  1094.             {
  1095.  
  1096.                 if (JedecGALType == GAL22V10)
  1097.                 {                               /* 22V10 => different sizes */
  1098.                                                 /* of OLMCs and additional  */
  1099.                                                 /* AS and RS rows           */
  1100.  
  1101.                     offset = (OLMCToRow22V10[olmc] + n)*colsize;
  1102.  
  1103.                     if (mode == 4)
  1104.                         offset = 0;                     /* asynch. reset */
  1105.                     else
  1106.                         if (mode == 5)
  1107.                             offset = 5764;              /* synch. preset */
  1108.                 }
  1109.                 else
  1110.                     offset = (olmc*8 + n)*colsize;  /* 16V8,20V8,20RA10: OLMC */
  1111.                                                     /* size is constant (=8)  */
  1112.  
  1113.                 if (!Jedec.GALLogic[offset + m])
  1114.                 {                                   /* fuse = 0? */
  1115.  
  1116.                     if (ANDflag)
  1117.                     {
  1118.                         if (AddByte(buff, (UBYTE)'*')) /* evaluate prod. term */
  1119.                             return(-1);
  1120.  
  1121.                         numofchar++;
  1122.                     }
  1123.  
  1124.                     ANDflag = 1;
  1125.                                             /*** GAL16V8 ***/
  1126.  
  1127.                     if (JedecGALType == GAL16V8)
  1128.                     {
  1129.                         if (mode == 1)                      /* get pin number */
  1130.                             pin = FuseToPin16Mode1[m/2];
  1131.  
  1132.                         if (mode == 2)
  1133.                             pin = FuseToPin16Mode2[m/2];
  1134.  
  1135.                         if (mode == 3)
  1136.                             pin = FuseToPin16Mode3[m/2];
  1137.                                                     /* was there a negation in */
  1138.                                                     /* in the declaration?     */
  1139.                         if (((*PinNamePtr(pin) == '/') && !(m % 2)) ||
  1140.                             ((*PinNamePtr(pin) != '/') &&  (m % 2)))
  1141.                         {
  1142.                             if (AddByte(buff, (UBYTE)'/'))
  1143.                                 return(-1);
  1144.  
  1145.                             numofchar++;
  1146.                         }
  1147.                                            /* write pin name without '/' */
  1148.                         if (*PinNamePtr(pin) == '/')
  1149.                         {
  1150.                             if (AddString(buff, (PinNamePtr(pin) + 1L)))
  1151.                                 return(-1);
  1152.                         }
  1153.                         else
  1154.                         {
  1155.                             if (AddString(buff, PinNamePtr(pin)))
  1156.                                 return(-1);
  1157.                         }
  1158.  
  1159.                         numofchar += (int)strlen(PinNamePtr(pin));
  1160.                     }
  1161.                     else
  1162.                     {                        /*** GAL20V8, 22V10, 20RA10 ***/
  1163.  
  1164.                         if (JedecGALType == GAL20V8)
  1165.                         {
  1166.                             if (mode == 1)               /* get pin number */
  1167.                                 pin = FuseToPin20Mode1[m/2];
  1168.  
  1169.                             if (mode == 2)
  1170.                                 pin = FuseToPin20Mode2[m/2];
  1171.  
  1172.                             if (mode == 3)
  1173.                                 pin = FuseToPin20Mode3[m/2];
  1174.                         }
  1175.  
  1176.                         if (JedecGALType == GAL22V10)
  1177.                             pin = FuseToPin22V10[m/2];
  1178.  
  1179.                         if (JedecGALType == GAL20RA10)
  1180.                             pin = FuseToPin20RA10[m/2];
  1181.  
  1182.                                           /* handle the negation sign */
  1183.                         if (JedecGALType == GAL22V10 &&
  1184.                             pin >= 14 && pin <= 23   &&
  1185.                             !Jedec.GALS1[23 - pin])
  1186.                         {          /* registered 22V10 OLMC:          */
  1187.                                    /* sign of feedback is contrary to */
  1188.                                    /* that of other GALs and/or modes */
  1189.  
  1190.                             if (((*PinNamePtr(pin) == '/') &&  (m % 2))  ||
  1191.                                 ((*PinNamePtr(pin) != '/') && !(m % 2)))
  1192.                             {
  1193.                                 if (AddByte(buff, (UBYTE)'/'))
  1194.                                     return(-1);
  1195.  
  1196.                                 numofchar++;
  1197.                             }
  1198.                         }
  1199.                         else
  1200.                         {                      /* was there a negation in */
  1201.                                                /* the pin declaration?    */
  1202.  
  1203.                             if (((*PinNamePtr(pin) == '/') && !(m % 2))  ||
  1204.                                 ((*PinNamePtr(pin) != '/') &&  (m % 2)))
  1205.                             {
  1206.                                 if (AddByte(buff, (UBYTE)'/'))
  1207.                                     return(-1);
  1208.  
  1209.                                 numofchar++;
  1210.                             }
  1211.                         }
  1212.                                                /* add pin name without */
  1213.                                                /* leading '/'          */
  1214.                         if (*PinNamePtr(pin) == '/')
  1215.                         {
  1216.                             if (AddString(buff, PinNamePtr(pin) + 1L))
  1217.                                 return(-1);
  1218.                         }
  1219.                         else
  1220.                         {
  1221.                             if (AddString(buff, PinNamePtr(pin)))
  1222.                                 return(-1);
  1223.                         }
  1224.  
  1225.                         numofchar += (int)strlen(PinNamePtr(pin));
  1226.                     }
  1227.  
  1228.  
  1229.                     if (numofchar > 60)
  1230.                     {                                         /* new line? */
  1231.                         if (AddString(buff, (UBYTE *)"\n        "))
  1232.                             return(-1);
  1233.  
  1234.                         numofchar = 8;
  1235.                     }
  1236.                 }
  1237.             }
  1238.         }
  1239.  
  1240.         if (result == 2)
  1241.         {                                       /* only '1' in all rows? */
  1242.             *buff = startbuff;                  /* then VCC              */
  1243.  
  1244.             if (AddString(buff, (UBYTE *)"VCC"))
  1245.                 return(-1);
  1246.  
  1247.             break;
  1248.         }
  1249.  
  1250.         n++;
  1251.     }
  1252.  
  1253.     if (AddString(buff, (UBYTE *)"\n\n"))         /* end of the equation */
  1254.         return(-1);
  1255.  
  1256.     return(0);
  1257. }
  1258.  
  1259.  
  1260.  
  1261.  
  1262.  
  1263. /******************************************************************************
  1264. ** Reasm()
  1265. *******************************************************************************
  1266. ** input:   buff    buffer in which the source file should be stored
  1267. **
  1268. ** output:     0:   no errors
  1269. **           <>0:   error
  1270. **
  1271. ** remarks: This function reassembles a JEDEC file and gernerates the
  1272. **          appropriate source file. The source file is stored in the buffer
  1273. **          described by "buff".
  1274. ******************************************************************************/
  1275.  
  1276. static int Reasm(struct ActBuffer buff)
  1277. {
  1278.     int     mode, n, numofpins, byte, tricon;
  1279.     int     firstOLMC, olmc, colsize, numofOLMCs;
  1280.     UBYTE   *ptr;
  1281.  
  1282.                                         /*** write type of GAL ***/
  1283.     switch (JedecGALType)
  1284.     {
  1285.         case GAL16V8:
  1286.                 if (AddString(&buff, (UBYTE *)"GAL16V8\n"))
  1287.                     return(-1);
  1288.  
  1289.                 numofpins  = 20;
  1290.                 numofOLMCs = 8;
  1291.                 firstOLMC  = 19;
  1292.                 colsize    = MAX_FUSE_ADR16 + 1;
  1293.                 break;
  1294.                
  1295.         case GAL20V8:
  1296.                 if (AddString(&buff, (UBYTE *)"GAL20V8\n"))
  1297.                     return(-1);
  1298.  
  1299.                 numofpins  = 24;
  1300.                 numofOLMCs = 8;
  1301.                 firstOLMC  = 22;
  1302.                 colsize    = MAX_FUSE_ADR20 + 1;
  1303.                 break;
  1304.  
  1305.         case GAL22V10:
  1306.                 if (AddString(&buff, (UBYTE *)"GAL22V10\n"))
  1307.                     return(-1);
  1308.  
  1309.                 numofpins  = 24;
  1310.                 numofOLMCs = 10;
  1311.                 firstOLMC  = 23;
  1312.                 colsize    = MAX_FUSE_ADR22V10 + 1;
  1313.                 break;
  1314.  
  1315.         case GAL20RA10:
  1316.                 if (AddString(&buff, (UBYTE *)"GAL20RA10\n"))
  1317.                     return(-1);
  1318.  
  1319.                 numofpins  = 24;
  1320.                 numofOLMCs = 10;
  1321.                 firstOLMC  = 23;
  1322.                 colsize    = MAX_FUSE_ADR20RA10 + 1;
  1323.                 break;
  1324.     }
  1325.  
  1326.  
  1327.  
  1328.     byte = 0;                             /*** write signature ***/
  1329.  
  1330.     for (n = 0; n < SIG_SIZE; n++)
  1331.     {
  1332.         byte |= Jedec.GALSig[n];                /* put 8 bits to one byte */
  1333.                                                 /* together               */
  1334.         if (!((n+1)%8))
  1335.         {
  1336.             if (!isprint(byte))
  1337.                 byte = '.';
  1338.  
  1339.             if (AddByte(&buff, (UBYTE)byte))
  1340.                 return(-1);
  1341.  
  1342.             byte = 0;
  1343.         }
  1344.  
  1345.         byte <<= 1;
  1346.     }
  1347.  
  1348.     if (AddString(&buff, (UBYTE *)"\n\n"))        /* new lines */
  1349.         return(-1);
  1350.  
  1351.  
  1352.                                         /*** write pin declaration ***/
  1353.     for (n = 1; n <= numofpins; n++)
  1354.     {
  1355.         if (JedecGALType == GAL16V8)
  1356.         {
  1357.             if (AddString(&buff, PinNamePtr(n)))
  1358.                 return(-1);
  1359.         }
  1360.         else
  1361.             if (AddString(&buff, PinNamePtr(n)))
  1362.                 return(-1);
  1363.  
  1364.         if (n == numofpins/2)
  1365.         {
  1366.             if (AddString(&buff, (UBYTE *)"\n"))
  1367.                 return(-1);
  1368.         }
  1369.         else
  1370.         {
  1371.             if (AddString(&buff, (UBYTE *)" "))
  1372.                 return(-1);
  1373.         }
  1374.     }
  1375.  
  1376.     if (AddString(&buff, (UBYTE *)"\n\n"))
  1377.         return(-1);
  1378.  
  1379.  
  1380.     mode = 0;
  1381.  
  1382.     if (JedecGALType == GAL16V8 || JedecGALType == GAL20V8)
  1383.     {
  1384.  
  1385.         if (!Jedec.GALAC0 && !Jedec.GALSYN)
  1386.         {                                   /* check mode of GAL  */
  1387.             ReasmError(1, 0);               /* error? then return */
  1388.             return(1);
  1389.         }
  1390.                                                 /* get mode of GAL */
  1391.         if (!Jedec.GALSYN)
  1392.         {                        /* if SYN = 0 then mode 3 */
  1393.             mode = 3;            /* (register)             */
  1394.         }
  1395.         else
  1396.         {
  1397.             if (Jedec.GALSYN && Jedec.GALAC0)
  1398.                 mode = 2;                           /* tristate mode */
  1399.             else
  1400.                 mode = 1;                           /* combinational mode */
  1401.         }
  1402.     }
  1403.  
  1404.                                         /*** generate the equations ***/
  1405.  
  1406.     for (olmc = 0; olmc < numofOLMCs; olmc++)
  1407.     {                                               /* all OLMCs */
  1408.  
  1409.         tricon = 0;
  1410.  
  1411.         if (OLMCOutput(olmc, mode))             /* is OLMC an output? */
  1412.         {
  1413.                                                 /* is there a negation in */
  1414.                                                 /* the pin declaration    */
  1415.  
  1416.             if (((*PinNamePtr(firstOLMC - olmc) == '/') &&  Jedec.GALXOR[olmc]) ||
  1417.                 ((*PinNamePtr(firstOLMC - olmc) != '/') && !Jedec.GALXOR[olmc]))
  1418.             {
  1419.                 if (AddByte(&buff, (UBYTE)'/'))
  1420.                     return(-1);
  1421.             }
  1422.                                             /* write pin name without '/' */
  1423.             if (*PinNamePtr(firstOLMC - olmc) == '/')
  1424.             {
  1425.                 if (AddString(&buff, ptr = PinNamePtr(firstOLMC - olmc) + 1L))
  1426.                     return(-1);
  1427.             }
  1428.             else
  1429.             {
  1430.                 if (AddString(&buff, ptr = PinNamePtr(firstOLMC - olmc)))
  1431.                     return(-1);
  1432.             }
  1433.  
  1434.                                         /*** get type of output ***/
  1435.  
  1436.             if (JedecGALType == GAL16V8 || JedecGALType == GAL20V8)
  1437.             {
  1438.  
  1439.                 if (mode == 2 || (mode == 3 && Jedec.GALAC1[olmc]))
  1440.                 {
  1441.                     if (AddString(&buff, (UBYTE *)".T"))
  1442.                         return(-1);
  1443.  
  1444.                     tricon = 1;             /* there is a tristate output, */
  1445.                 }                           /* so set tricon flag          */
  1446.  
  1447.                 if (mode == 3 && !Jedec.GALAC1[olmc])
  1448.                     if (AddString(&buff, (UBYTE *)".R"))
  1449.                         return(-1);
  1450.  
  1451.                 if (AddString(&buff, (UBYTE *)" = "))
  1452.                     return(-1);
  1453.  
  1454.                 n = 0;                   /* if there is a tristate control */
  1455.  
  1456.                 if (mode == 2 || (mode == 3 && Jedec.GALAC1[olmc]))
  1457.                     n++;                 /* skip first row of OLMC */
  1458.  
  1459.                 if (MakeEquation(&buff, olmc, colsize, mode, n, 8 - n))
  1460.                     return(-1);
  1461.  
  1462.                                             /* write the equation      */
  1463.                 if (tricon)                 /* of the tristate control */
  1464.                 {
  1465.                                             /* write pin name with leading */
  1466.                                             /* '/' if there is one         */
  1467.                     if (AddString(&buff, PinNamePtr(firstOLMC - olmc)))
  1468.                         return(-1);
  1469.  
  1470.                     if (AddString(&buff, (UBYTE *)".E = ")) /*tristate enable*/
  1471.                         return(-1);
  1472.                                                             /* write equation*/
  1473.                     if (MakeEquation(&buff, olmc, colsize, mode, 0, 1))
  1474.                         return(-1);
  1475.                 }
  1476.  
  1477.             }
  1478.  
  1479.  
  1480.  
  1481.             if (JedecGALType == GAL22V10)
  1482.             {
  1483.  
  1484.                 if (Jedec.GALS1[olmc])
  1485.                 {                                   /* get type of output */
  1486.                     if (AddString(&buff, (UBYTE *)".T = "))
  1487.                         return(-1);
  1488.                 }
  1489.                 else
  1490.                     if (AddString(&buff, (UBYTE *)".R = "))
  1491.                         return(-1);
  1492.  
  1493.                                                 /* write output's equation */
  1494.                 if (MakeEquation(&buff, olmc, colsize, 0, 1,
  1495.                                  OLMCSize22V10[olmc] - 1))
  1496.                     return(-1);
  1497.                                                 /* write equation of */
  1498.                                                 /* tristate control  */
  1499.  
  1500.                                         /* write pin name with leading */
  1501.                                         /* '/' if there is one         */
  1502.                 if (AddString(&buff, PinNamePtr(firstOLMC - olmc)))
  1503.                     return(-1);
  1504.  
  1505.                 if (AddString(&buff, (UBYTE *)".E = ")) /* tristate enable */
  1506.                     return(-1);
  1507.  
  1508.                                                 /* write equation */
  1509.  
  1510.                 if (MakeEquation(&buff, olmc, colsize, 0, 0, 1))
  1511.                     return(-1); 
  1512.  
  1513.  
  1514.             }
  1515.  
  1516.  
  1517.  
  1518.             if (JedecGALType == GAL20RA10)
  1519.             {
  1520.                                                 /* write equation of output */
  1521.                 if (RowActive(ToOLMC20RA10[9 - olmc] + 2, JedecGALType) == 2 &&
  1522.                     RowActive(ToOLMC20RA10[9 - olmc] + 3, JedecGALType) == 2)
  1523.                 {
  1524.                     if (AddString(&buff, (UBYTE *)" = "))/* if ARST and APRST */
  1525.                         return(-1);                      /* = VCC, then       */
  1526.                 }                                        /* tristate output   */
  1527.                 else
  1528.                 {
  1529.                     if (AddString(&buff, (UBYTE *)".R = "))
  1530.                         return(-1);
  1531.                 }
  1532.  
  1533.                 if (MakeEquation(&buff, olmc, colsize, 0, 4, 4))
  1534.                     return(-1);
  1535.  
  1536.                                         /* write pin name with leading */
  1537.                                         /* '/' if there is one         */
  1538.                 if (AddString(&buff, PinNamePtr(firstOLMC - olmc)))
  1539.                     return(-1);
  1540.  
  1541.                 if (AddString(&buff, (UBYTE *)".E = "))
  1542.                     return(-1);
  1543.  
  1544.                 if (MakeEquation(&buff, olmc, colsize, 0, 0, 1))
  1545.                     return(-1);
  1546.  
  1547.  
  1548.                 if (RowActive(olmc * 8 + 1, JedecGALType))
  1549.                 {
  1550.                     if (AddString(&buff, ptr))      /* write equation of */
  1551.                         return(-1);                 /* Clock             */
  1552.  
  1553.                     if (AddString(&buff, (UBYTE *)".CLK = "))
  1554.                         return(-1);
  1555.  
  1556.                     if (MakeEquation(&buff, olmc, colsize, 0, 1, 1))
  1557.                         return(-1);
  1558.                 }
  1559.  
  1560.  
  1561.                 if (RowActive(olmc*8 + 2, JedecGALType))
  1562.                 {
  1563.                     if (AddString(&buff, ptr))        /* write equation of  */
  1564.                         return(-1);                   /* asynchronous reset */
  1565.  
  1566.                     if (AddString(&buff, (UBYTE *)".ARST = "))
  1567.                         return(-1);
  1568.  
  1569.                     if (MakeEquation(&buff, olmc, colsize, 0, 2, 1))
  1570.                         return(-1);
  1571.                 }
  1572.  
  1573.  
  1574.                 if (RowActive(olmc*8 + 3, JedecGALType))
  1575.                 {
  1576.                     if (AddString(&buff, ptr))         /* write equation of   */
  1577.                         return(-1);                    /* asynchronous preset */
  1578.  
  1579.                     if (AddString(&buff, (UBYTE *)".APRST = "))
  1580.                         return(-1);
  1581.  
  1582.                     if (MakeEquation(&buff, olmc, colsize, 0, 3, 1))
  1583.                         return(-1);
  1584.                 }
  1585.             }
  1586.         }
  1587.     }
  1588.  
  1589.  
  1590.                                         /*** write asynchronous reset and ***/
  1591.                                         /*** synchronous preset           ***/
  1592.     if (JedecGALType == GAL22V10)
  1593.     {
  1594.  
  1595.         if (RowActive(0, JedecGALType))
  1596.         {
  1597.             if (AddString(&buff, (UBYTE *)"AR = "))     /* asyn. reset */
  1598.                 return(-1);
  1599.  
  1600.             if (MakeEquation(&buff, olmc, colsize, 4, 0, 1))
  1601.                 return(-1);
  1602.         }
  1603.  
  1604.         if (RowActive(131, JedecGALType))
  1605.         {
  1606.             if (AddString(&buff, (UBYTE *)"SP = "))     /* synch. preset */
  1607.                 return(-1);
  1608.  
  1609.             if (MakeEquation(&buff, olmc, colsize, 5, 0, 1))
  1610.                 return(-1);
  1611.         }
  1612.  
  1613.     }
  1614.  
  1615.                                         /*** write ending text ***/
  1616.  
  1617.     if (AddString(&buff,"DESCRIPTION:\nThis is a reassembled file. Used JEDEC file: '"))
  1618.         return(-1);
  1619.  
  1620.     if (AddString(&buff, (UBYTE *)&filename[0]))
  1621.         return(-1);
  1622.  
  1623.     if (AddString(&buff, (UBYTE *)"'\n\n"))
  1624.         return(-1);
  1625.  
  1626.  
  1627.     return(0);                            /* no errors, finish*/
  1628. }
  1629.  
  1630.  
  1631.  
  1632.  
  1633.  
  1634. /******************************************************************************
  1635. ** Reassembler()
  1636. *******************************************************************************
  1637. ** input:   none
  1638. ** output:  none
  1639. **
  1640. ** remarks: reassembles a JEDEC file and writes the source file
  1641. ******************************************************************************/
  1642.  
  1643. void Reassembler(void)
  1644. {
  1645.     struct  Buffer          *reasm_buff;
  1646.     struct  ActBuffer       mybuff;
  1647.     BPTR    fh;
  1648.     UBYTE   *filebuffer, *filebuffer2;
  1649.     int     result;
  1650.  
  1651.  
  1652.     if (MyFileReq(AppStrings[MSG_LOADJED].as_Str, ".jed", YES, LOAD))
  1653.     {
  1654.         if (!(GetJedec((UBYTE *)&path[0])))
  1655.         {                                   /* get the JEDEC file */
  1656.  
  1657.             if (!PinNameRequester(JedecGALType))
  1658.                 return;
  1659.  
  1660.  
  1661.             if (!(reasm_buff = (struct Buffer *)
  1662.                   AllocMem((long)sizeof(struct Buffer),MEMF_PUBLIC|MEMF_CLEAR)))
  1663.             {
  1664.                 ErrorReq(2);        /* out of memory */
  1665.                 return;
  1666.             }
  1667.  
  1668.             mybuff.ThisBuff = reasm_buff;
  1669.             mybuff.Entry    = (UBYTE *)(&reasm_buff->Entries[0]);
  1670.             mybuff.BuffEnd  = (UBYTE *)reasm_buff + (long)sizeof(struct Buffer);
  1671.  
  1672.  
  1673.             if (!Reasm(mybuff) && MyFileReq(AppStrings[MSG_WRITE_SOURCE].as_Str,
  1674.                                             ".pld", YES, SAVE))
  1675.             {
  1676.                 PrintText(AppStrings[MSG_WRITING_SOURCE].as_Str, 1);
  1677.  
  1678.                 if ((fh = Open(&path[0], (long)MODE_NEWFILE)))
  1679.                 {
  1680.                     for (;;)
  1681.                     {
  1682.                         filebuffer = filebuffer2 = mybuff.Entry;
  1683.  
  1684.                         while (filebuffer2 < mybuff.BuffEnd)
  1685.                         {                   /* get buffer size */
  1686.                             if (!*filebuffer2)
  1687.                                 break;
  1688.  
  1689.                             filebuffer2++;
  1690.                         }
  1691.                                                 /* write buffer */
  1692.                         result = Write(fh, (char *)filebuffer,
  1693.                                        (long)(filebuffer2-filebuffer));
  1694.  
  1695.                         if (result == -1L)
  1696.                         {                       /* write error?        */
  1697.                             Close(fh);          /* yes, then shut down */
  1698.                             FreeBuffer(reasm_buff);
  1699.                             PrintText(AppStrings[MSG_ERROR].as_Str, 0);
  1700.                             ErrorReq(13);
  1701.                             return;
  1702.                         }
  1703.  
  1704.                         if (!mybuff.ThisBuff->Next) /* if there is no more */
  1705.                             break;                  /* buffer, break loop  */
  1706.  
  1707.                         mybuff.ThisBuff = mybuff.ThisBuff->Next;
  1708.                         mybuff.Entry    = (UBYTE *)(&mybuff.ThisBuff->Entries[0]);
  1709.                         mybuff.BuffEnd  = (UBYTE *)mybuff.ThisBuff +
  1710.                                           (long)sizeof(struct Buffer);
  1711.                     }
  1712.  
  1713.                     Close(fh);
  1714.                 }
  1715.                 else
  1716.                 {
  1717.                     FreeBuffer(reasm_buff);         /*error?, then cancel */
  1718.                     PrintText(AppStrings[MSG_ERROR].as_Str, 0);
  1719.                     ErrorReq(13);                  /* can't open file     */
  1720.                     return;
  1721.                 }
  1722.  
  1723.                 PrintText(AppStrings[MSG_LOWER_OK].as_Str, 0);
  1724.             }
  1725.  
  1726.             FreeBuffer(reasm_buff);         /* free allocated memory */
  1727.         }
  1728.     }
  1729. }
  1730.  
  1731.  
  1732.  
  1733.  
  1734.  
  1735. /******************************************************************************
  1736. ** ReasmError()
  1737. *******************************************************************************
  1738. ** input:   errornum    error number to be printed
  1739. **          pinnum      pinnumber to be printed
  1740. **
  1741. ** output:  none
  1742. **
  1743. ** remarks: prints an error messages
  1744. ******************************************************************************/
  1745.  
  1746. static void ReasmError(int errornum, int pinnum)
  1747. {
  1748. #define PINNUM_POS 7
  1749.  
  1750.     char    string[40];
  1751.  
  1752.     switch (errornum)
  1753.     {
  1754.         case  1:
  1755.              TxtRequest(AppStrings[MSG_REASM_ERR].as_Str,
  1756.                         AppStrings[MSG_CANCEL_GAD].as_Str, NULL);
  1757.  
  1758.              PrintText(AppStrings[MSG_ERR_REASM1].as_Str, 1);
  1759.              break;
  1760.  
  1761.         case  2:
  1762.             strcpy(string, AppStrings[MSG_ERR_REASM2].as_Str);
  1763.             sprintf(&string[PINNUM_POS], "%2d", pinnum);
  1764.             string[PINNUM_POS + 2] = ':';
  1765.             TxtRequest(string, AppStrings[MSG_CANCEL_GAD].as_Str, NULL);
  1766.             break;
  1767.  
  1768.         case  3:
  1769.             strcpy(string, AppStrings[MSG_ERR_REASM3].as_Str);
  1770.             sprintf(&string[PINNUM_POS], "%2d", pinnum);
  1771.             string[PINNUM_POS + 2] = ':';
  1772.             TxtRequest(string, AppStrings[MSG_CANCEL_GAD].as_Str, NULL);
  1773.             break;
  1774.  
  1775.         case  4:
  1776.             strcpy(string, AppStrings[MSG_ERR_REASM4].as_Str);
  1777.             sprintf(&string[PINNUM_POS], "%2d", pinnum);
  1778.             string[PINNUM_POS + 2] = ':';
  1779.             TxtRequest(string, AppStrings[MSG_CANCEL_GAD].as_Str, NULL);
  1780.             break;
  1781.  
  1782.         case  5:
  1783.             strcpy(string, AppStrings[MSG_ERR_REASM5].as_Str);
  1784.             sprintf(&string[PINNUM_POS], "%2d", pinnum);
  1785.             string[PINNUM_POS + 2] = ':';
  1786.             TxtRequest(string, AppStrings[MSG_CANCEL_GAD].as_Str, NULL);
  1787.             break;
  1788.  
  1789.         case  6:
  1790.             strcpy(string, AppStrings[MSG_ERR_REASM6].as_Str);
  1791.             sprintf(&string[PINNUM_POS], "%2d", pinnum);
  1792.             string[PINNUM_POS + 2] = ':';
  1793.             TxtRequest(string, AppStrings[MSG_CANCEL_GAD].as_Str, NULL);
  1794.             break;
  1795.  
  1796.         case  7:
  1797.             strcpy(string, AppStrings[MSG_ERR_REASM7].as_Str);
  1798.             sprintf(&string[PINNUM_POS], "%2d", pinnum);
  1799.             string[PINNUM_POS + 2] = ':';
  1800.             TxtRequest(string, AppStrings[MSG_CANCEL_GAD].as_Str, NULL);
  1801.             break;
  1802.  
  1803.         case  8:
  1804.             strcpy(string, AppStrings[MSG_ERR_REASM8].as_Str);
  1805.             sprintf(&string[PINNUM_POS], "%2d", pinnum);
  1806.             string[PINNUM_POS + 2] = ':';
  1807.             TxtRequest(string, AppStrings[MSG_CANCEL_GAD].as_Str, NULL);
  1808.             break;
  1809.  
  1810.         case  9:
  1811.             strcpy(string, AppStrings[MSG_ERR_REASM9].as_Str);
  1812.             sprintf(&string[PINNUM_POS], "%2d", pinnum);
  1813.             string[PINNUM_POS + 2] = ':';
  1814.             TxtRequest(string, AppStrings[MSG_CANCEL_GAD].as_Str, NULL);
  1815.             break;
  1816.  
  1817.         case 10:
  1818.             strcpy(string, AppStrings[MSG_ERR_REASM10].as_Str);
  1819.             sprintf(&string[PINNUM_POS], "%2d", pinnum);
  1820.             string[PINNUM_POS + 2] = ':';
  1821.             TxtRequest(string, AppStrings[MSG_CANCEL_GAD].as_Str, NULL);
  1822.             break;
  1823.  
  1824.     }
  1825. }
  1826.  
  1827.  
  1828.  
  1829.  
  1830.  
  1831. /* EOF */
  1832.